package com.luyue.zagj.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.media.Image;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;

/**
 * Created by Chen qin lang on 2016/12/20.
 * 邮箱 :   619766577@qq.com
 */
public class ImagePager extends PagerAdapter {
    public Context context;
    public ArrayList<Drawable> drawables;

    public ImagePager(Context context, ArrayList<Drawable> drawables) {
        this.context=context;
        this.drawables=drawables;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView=new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        position%=drawables.size();
        imageView.setBackgroundDrawable(drawables.get(position));
        container.addView(imageView);

        return imageView;
    }

    @Override
    public int getCount() {
        return drawables.size()*10;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }
}
